//获取消息公告内容
getInfo(1,1)
var pageNum=1;
console.log(localStorage.uuid)
function getInfo(t,pageNum){
	$.ajax({
		type:"GET",
		url:"http://120.76.201.26:8088/msg/message?t="+t+"&p="+pageNum+"&uuid="+localStorage.uuid+"&vid="+localStorage.vid,
		async:true,
		success:function(e){
			console.log(e.code)
			if(e.data.message.length>0){
				$(".null").css("display","none");
				for(var i=0,messageLength=e.data.message.length;i<messageLength;i++){
					var html='<div><a href="javascript:;">'+e.data.message[i].create_time+'</a><div><h2>'+e.data.message[i].type+'</h2><h6>'+e.data.message[i].title+'<br/>'+e.data.message[i].message+'</h6><span class="income" url='+e.data.message[i].url+'>查看详情<img src="../../img/personalImg/right.png"></span></div></div>'
					$(".navCont").eq(t-1).append(html)
				}
				pageNum++;
				getInfo(t,pageNum)
				$(".income").on("click",function(){
					mui.openWindow({
						url: $(this).attr("url"), 
						id:$(this).attr("url").split(".html")[0]
					});
				})
			}else{
				$(".null").css("display","block");
			}
			//判定是否有未读公告、消息
			if(e.data.not_read_notice>0){
				$(".null").css("display","none");
				$(".navTop span a").eq(1).css("display","block")
				$(".navTop>span").eq(1).on("click",function(){
					//阅读消息接口
					if(localStorage.logintoken){
						readMessageUser()
					}else{
						readMessage()
					}
				})
			}else{
				$(".navTop span a").eq(1).css("display","none")
			}
			if(e.data.not_read_jpush>0){
				$(".navTop span a").eq(0).css("display","block")
				$(".navTop>span").eq(0).on("click",function(){
					//阅读消息接口
					if(localStorage.logintoken){
						readMessageUser()
					}else{
						readMessage()
					}
				})
			}else{
				$(".navTop span a").eq(0).css("display","none")
			}
		}
	});
}

function readMessage(){
	$.ajax({
		type:"GET",
		url:"http://120.76.201.26:8088/msg/read?uuid="+localStorage.uuid+"&vid="+localStorage.vid,
		async:true,
		success:function(e){
			console.log(e.code)
		}
	});
}
function readMessageUser(){
	$.ajax({
		type:"GET",
		url:"http://120.76.201.26:8088/msg/read?uuid="+localStorage.uuid+"&vid="+localStorage.vid,
		async:true,
		beforeSend: function(request) {
			request.setRequestHeader("Authorization","Basic"+localStorage.logintoken);
		},
		success:function(e){
			console.log(e.code)
		}
	});
}


$(".navTop>span").on("click",function(){
	$(".navCont").eq($(this).index()).empty();
	pageNum=1;
	getInfo($(this).index()+1,pageNum)
	$(".navTop>span").removeClass("active");
	$(this).addClass("active");
	$(".navCont").css("display","none").attr("check","false");
	$(".navCont").eq($(this).index()).css("display","block").attr("check","true")
})
//清空效果
$(".clear_help").on("click",function(){
	if($(".navCont").eq(0).attr("check")=="true"){
		//清除消息
		clearMessage(1)
		
	}else{
		//清除公告
		clearMessage(2)
//		$(".navCont").eq(1).empty();
	}
})

//清空消息接口
function clearMessage(type){
	$.ajax({
		type:"get",
		url:"http://120.76.201.26:8088/msg/del?t="+type+"&uuid="+localStorage.uuid+"&vid="+localStorage.vid,
		async:true,
		success:function(e){
			console.log(e)
			if(e.code==0){
				$(".navCont").eq(type-1).empty();
				$(".null").css("display","block")
			}
		}
	});
}


//跳转到响应的详情页面
document.getElementsByClassName("exchange")[0].addEventListener('tap', function() {
	mui.openWindow({
		url: 'exchange.html', 
		id:'exchange'
	});
});

document.getElementsByClassName("notice")[0].addEventListener('tap', function() {
	mui.openWindow({
		url: 'notice.html', 
		id:'notice'
	});
});
